from typing import List


class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        res = {}
        for s in strs:
            sa = ''.join(sorted(s))
            if sa in res:
                res[sa].append(s)
            else:
                res[sa] = [s]
        return [v for v in res.values()]


if __name__ == "__main__":
    s = Solution()
    print(s.groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))
